package com.csnf.service.impl;

import com.csnf.feign.AccountFeignClient;
import com.csnf.mapper.OrderMapper;
import com.csnf.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    OrderMapper orderMapper;

    @Autowired
    AccountFeignClient accountFeignClient;


    @Transactional
    @Override
    public int addOrder(String userId, String productCode, int count) {

        //正常的逻辑，应该是请求商品服务，获取商品的单价

        int money = 8 * count;


        //先扣减余额 （Feign远程调用）
        accountFeignClient.updateAccount(userId, money);


        return orderMapper.addOrder(userId, productCode, count, money);
    }
}
